import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import { resolve } from 'path'

export default defineConfig({
  plugins: [uni()],
  base:'./',
  resolve: {
    alias: {
      '@': resolve(__dirname, './')
    },
    extensions: ['.ts', '.js', '.vue', '.json']
  },
  // 添加 uni-app 特定配置
  define: {
    __UNI_FEATURE_I18N_EN__: false,
    __UNI_FEATURE_I18N_ES__: false,
    __UNI_FEATURE_I18N_FR__: false,
    __UNI_FEATURE_I18N_ZH_HANS__: false,
    __UNI_FEATURE_I18N_ZH_HANT__: false,
  },
  // 配置依賴分析
  build: {
    rollupOptions: {
      external: [],
      output: {
        manualChunks: undefined
      }
    }
  },
  server: {
    port: 3000,
    open: true,
    proxy: {
      // 代理 API 请求
      '/api': {
        target: 'https://hongjiang.hj-hr.com',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/api/, '/api'),
        configure: (proxy, options) => {
          // 代理事件处理
          proxy.on('error', (err, req, res) => {
            console.log('代理错误:', err)
          })
          proxy.on('proxyReq', (proxyReq, req, res) => {
            console.log('代理请求:', req.method, req.url)
          })
          proxy.on('proxyRes', (proxyRes, req, res) => {
            console.log('代理响应:', proxyRes.statusCode, req.url)
          })
        }
      }
    }
  }
}) 